package com.hopu.v1.service.front.question.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hopu.v1.mapper.front.question.FQuestionsMapper;
import com.hopu.v1.pojo.question.Questions;
import com.hopu.v1.pojo.question.QuestionsBanks;
import com.hopu.v1.service.front.question.FQuestionsBanksService;
import com.hopu.v1.mapper.front.question.FQuestionsBanksMapper;
import com.hopu.v1.vo.QuestionBanksVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 *
 */
@Service
public class FQuestionsBanksServiceImpl extends ServiceImpl<FQuestionsBanksMapper, QuestionsBanks>
    implements FQuestionsBanksService {

    @Autowired
    private FQuestionsBanksMapper fQuestionsBanksMapper;

    @Autowired
    private FQuestionsMapper fQuestionsMapper;

    @Override
    public List<QuestionBanksVo> getQuestionBanks(Page<QuestionsBanks> page, String name, Integer subjectId) {
        LambdaQueryWrapper<QuestionsBanks> questionsBanksLambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (name != null){
            questionsBanksLambdaQueryWrapper.like(QuestionsBanks::getName,name);
        }
        if (subjectId != null){
            questionsBanksLambdaQueryWrapper.eq(QuestionsBanks::getSubjectId,subjectId);
        }
        List<QuestionsBanks> questionsBanks = fQuestionsBanksMapper.selectList(page, questionsBanksLambdaQueryWrapper);
        List<QuestionBanksVo> questionBanksVos = new ArrayList<>();
        for (QuestionsBanks questionsBank : questionsBanks) {
            QuestionBanksVo questionBanksVo = new QuestionBanksVo();
            questionBanksVo.setQuestionsBanks(questionsBank);
            questionBanksVos.add(questionBanksVo);
            questionBanksVo.setCount(fQuestionsMapper.selectCount(new LambdaQueryWrapper<Questions>().eq(Questions::getQuestionBanksId,questionsBank.getId())));
        }
        return questionBanksVos;
    }

    @Override
    public int deleteQuestionBanks(int id) {
        return 0;
    }
}




